package com.dingdang.util;
import java.util.HashMap;
import java.util.Map;

public class RestControllerHelper {
    /**
     * RestControllerHelper的toJson常量
     */
    private static final String RESULT_CODE = "code";
    private static final String RESULT_MSG = "msg";
    private static final String RESULT_RET = "ret";
    private static final String RESULT_DATA = "data";
    private static final String RESULT_INFO = "info";

    /**
     * ret
     * 200: 成功。
     * 401: 当前请求需要用户验证。
     * 403：权限错误。
     * 404: 请求的资源未找到。
     * 408：请求超时。
     */
    public static final int SUCCESS = 200;
    public static final int UNLOGIN = 401;
    public static final int FORBIDDEN = 403;
    public static final int NOT_FOUND = 404;
    public static final int TIMEOUT = 408;
    /**
     * 里层code
     * 0: 成功。
     * 1:状态码
     */
    public static final int CODE_0 = 0;
    public static final int CODE_1 = 1;
    /**
     * 最外层 MSg
     * 0: 获取失败
     * 1: 获取成功
     */
    public static final String REQUEST_SUCCESS = "获取成功";
    public static final String REQUEST_ERROR = "获取失败";
    /**
     *  code: 状态码
     *  msg: 状态码消息
     *  data: 数据
     */
    private Integer ret;
    private Integer code;
    private String msg;
    private Object data;

    public RestControllerHelper() {
        this.ret = SUCCESS;
        this.code = CODE_1;
    }
    /**
     * toJsonMap
     * @return
     */
    public Map<String,Object> toJsonMap() {
        Map<String,Object> map = new HashMap<>(3);
        Map<String,Object> map1 = new HashMap<>(3);
        map.put(RESULT_RET,this.SUCCESS);
        map.put(RESULT_MSG,REQUEST_SUCCESS);
        map.put(RESULT_DATA,map1);

        map1.put(RESULT_CODE,this.code);
        map1.put(RESULT_MSG,this.msg);
        map1.put(RESULT_INFO,this.data);

        return map;
    }
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }
    public Integer getRet() {
        return ret;
    }

    public void setRet(Integer ret) {
        this.ret = ret;
    }
    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
